﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OdeToFoo.Filters;

namespace OdeToFoo.Controllers
{
    [Log]
    public class CuisineController : Controller
    {
        //
        // GET: /Cuisine/

        [ActionName("post")]
        [HttpGet]
        public ActionResult PostRequest(string name)
        {
            var message = Server.HtmlEncode(name);
            return Content(name);
        }





        public ActionResult Search(string name = "you did not enter anything for name") //MVC will look for everything a parameter to match "name" "cuisine/{name}",
        {
            var message = Server.HtmlEncode(name); //prevent XXS attack
            if (message == "microsoft")
                return RedirectPermanent("http://microsoft.com");
            else if (message == "index")
                return RedirectToAction("Index", "Home");

            return Content( message);
        }
        public ActionResult Redir(string name = "fail to redirect")
        {
            var message = Server.HtmlEncode(name);
            return RedirectToRoute("Default", new {controller = "Home", action = "About" });
        }
        public ActionResult GetJson(string name = "")
        {
            var message = Server.HtmlEncode(name);
            return Json(new { Message = message, Name = "Scott" }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult File(string name = "")
        {
            var message = Server.HtmlEncode(name);
            return File(Server.MapPath("~/Content/site.css"), "text/css");
        }
    }
}
